package com.ddn.service.hall.impl;

import com.ddn.mapper.hall.ConferenceMapper;
import com.ddn.model.hall.Conference;
import com.ddn.model.hall.ConferenceBarVO;
import com.ddn.model.hall.ConferencePieVO;
import com.ddn.service.hall.ConferenceService;
import com.ddn.util.R;
import com.ddn.util.ResultData;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/*
  ❀❀❀---扎根---❀❀❀
    ❤ @libing ❤
  
*/
@Service
public class ConferenceServiceImpl implements ConferenceService {

    @Autowired
    private ConferenceMapper conferenceMapper;

    /**
     * 动态下拉框
     * @return
     */
    @Override
    public List<Conference> getConSubject() {
        List<Conference> conferenceList = conferenceMapper.getConSubject();
        return conferenceList;
    }

    /**
     * 查找全部会议厅信息
     * @param map
     * @return
     */
    @Override
    public ResultData findAllConference(HashMap<String, Object> map) {
        String pageNo = (String) map.get("page");
        String pageSize = (String) map.get("limit");
        PageHelper.startPage(Integer.parseInt(pageNo),Integer.parseInt(pageSize));

        List<Conference> conferenceList= conferenceMapper.findAllConference(map);

        PageInfo<Conference> info =new PageInfo<>(conferenceList);

        long l = info.getTotal();
        if (conferenceList != null) {
            return ResultData.ok(conferenceList,l);
        }
        return ResultData.fail();
    }

    /**
     * S删除会议厅信息
     * @param map
     * @return
     */
    @Override
    public ResultData deleteConference(HashMap<String, Object> map) {

        int i =conferenceMapper.deleteConference(map);
        if (i >0) {
            return ResultData.ok();
        }
        return ResultData.fail();
    }

    /**
     * 添加会议厅信息
     * @param map
     * @return
     */
    @Override
    public ResultData addConference(HashMap<String, Object> map) {
        int i =conferenceMapper.addConference(map);
        if (i >0) {
            return ResultData.ok();
        }
        return ResultData.fail();
    }

    /**
     * 编辑会议厅信息
     * @param map
     * @return
     */
    @Override
    public ResultData updateConference(HashMap<String, Object> map) {
        int i =conferenceMapper.updateConference(map);
        if (i >0) {
            return ResultData.ok();
        }
        return ResultData.fail();
    }

    /**
     * 批量删除会议厅信息
     * @param ids
     * @return
     */
    @Override
    public ResultData batchConference(List<Integer> ids) {
        int i =conferenceMapper.batchConference(ids);
        if (i >0) {
            return ResultData.ok();
        }
        return ResultData.fail();
    }

    /**
     *
     * @return
     */
    @Override
    public ResultData selectConSubject() {
        List<String> conSubjects = conferenceMapper.selectConSubject();
//        System.out.println(conSubjects);
        if (conSubjects !=null) {
            return ResultData.ok(conSubjects);
        }
        return ResultData.fail();
    }

    @Override
    public ResultData barConSubject() {
        List<ConferenceBarVO> conferenceBarVOList = conferenceMapper.barConSubject();
        System.out.println("conferenceBarVOList = " + conferenceBarVOList);
        if (conferenceBarVOList !=null) {
            return ResultData.ok(conferenceBarVOList);
        }
        return ResultData.fail();
    }

    @Override
    public ResultData pieConSubject() {
        List<ConferencePieVO> conferencePieVOS = conferenceMapper.pieConSubject();
//        System.out.println("conferenceBarVOList = " + conferencePieVOS);
        if (conferencePieVOS !=null) {
            return ResultData.ok(conferencePieVOS);
        }
        return ResultData.fail();
    }
}
